use crate::{handles::*, middlewares::Authenticate};
use poem::{Endpoint, EndpointExt, Route};

#[allow(unused_imports)]
use poem::{delete, get, post, put};

pub(super) fn router() -> Route {
    Route::new()
        .at("/ping", get(ping::ping))
        .at("/users/login", post(guard::login))
        .at("/users/info", get(guard::info))
        .nest_no_strip("/", privileged())
}

#[rustfmt::skip]
fn privileged() -> impl Endpoint {
    Route::new()
        .at("/departments",               get(department::batch))
        .at("/department",                post(department::create)
                                         .put(department::update))
        .at("/department/:id",            delete(department::delete))
        .at("/department/positions/:id",  get(department::positions))
        .at("/department/personnels/:id", get(department::personnels))
        .at("/position",                  post(position::create)
                                         .put(position::update))
        .at("/position/:id" ,             delete(position::delete))
        .at("/position/personnels/:id",   get(position::personnels))
        .at("/personnels",                get(personnel::batch))
        .at("/personnel",                 post(personnel::create)
                                         .put(personnel::update))
        .at("/personnel/:id",             get(personnel::get))
        .at("/resignations",              get(resignation::batch))
        .at("/resignation/:id",           post(personnel::delete))
        .at("/statement/entry",           get(statement::entry))
        .at("/statement/resign",          get(statement::resign))
        .with(Authenticate)
}
